package logic

import (
	"context"
	"product/model/mysql"

	"product/productrpc/internal/svc"
	"product/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *productrpc.AddRequest) (*productrpc.AddResponse, error) {
	// todo: add your logic here and delete this line

	Add := mysql.Product{
		Product: in.Product,
		Img:     in.Img,
		Status:  in.Status,
	}
	mysql.DB.Debug().Model(&Add).Create(&Add)

	return &productrpc.AddResponse{Id: int64(Add.ID)}, nil
}
